import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/layout'
  },
  // 配置登录页面路由
  {
    path: '/login',
    // 设置路由的名称，命名路由。
    name: 'login',
    component: () => import('@/views/login/index.vue')
  },
  // 配置页面组件布局路由
  {
    path: '/layout',
    name: 'layout',
    redirect: '/layout/',
    component: () => import('../views/layout/index.vue'),
    // 将四个主页面配置为 tab-bar 的子路由
    children: [
      {
        // 默认子路由
        path: '',
        name: 'home',
        component: () => import('../views/home/index.vue')
      },
      {
        path: 'qa',
        name: 'qa',
        component: () => import('../views/qa/index.vue')
      },
      {
        path: 'video',
        name: 'video',
        component: () => import('../views/video/index.vue')
      },
      {
        path: 'my',
        name: 'my',
        component: () => import('../views/my/index.vue')
      }
    ]
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/search/index.vue')
  },
  // 将该页面配置到根级路由
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/article/index.vue'),
    // 开启 props 传参，说白了就是把路由参数映射到组件的 props 中
    props: true
  },
  {
    path: '/user/profile',
    name: 'user-profile',
    component: () => import('@/views/user-profile')
  }
]

const router = new VueRouter({
  routes
})

export default router
